#include "motor_config.h"
#include "gp_layout_map.h"

int get_sid_in_moudle_djp(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 29;
        }
        break;
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 30;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 31;
        }
        break;
        case MotorType::MT_PUMP:
        {
            sidRet = 44;
        }
        break;
        case MotorType::MT_PUMP_SMALL:
        {
            sidRet = 45;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_djq(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 12;
        }
        break;
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 17;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 28;
        }
        break;
        case MotorType::MT_PUMP:
        {
            sidRet = 46;
        }
        break;
        case MotorType::MT_JAW:
        {
            sidRet = 19;
        }
        break;
        case MotorType::MT_JAW_Z:
        {
            sidRet = 18;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_dp1(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 20;
        }
        break;
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 21;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 1;
        }
        break;
        case MotorType::MT_JAW_Z:
        {
            sidRet = 22;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_dp8(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 82;
        }
        break;
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 83;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 15;
        }
        break;
        case MotorType::MT_PUMP:
        {
            sidRet = 14;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_openlid(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 11;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 10;
        }
        break;
        case MotorType::MT_JAW:
        {
            sidRet = 81;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_seal(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_Y:
        {
            sidRet = 0;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 13;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_qpcr1(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 48;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 45;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid_in_moudle_qpcr2(int motorTypeIn)
{
    int sidRet = 0;
    switch (motorTypeIn)
    {
        case MotorType::MT_AXIS_X:
        {
            sidRet = 55;
        }
        break;
        case MotorType::MT_AXIS_Z:
        {
            sidRet = 52;
        }
        break;
        default:
        break;
    }
    return sidRet;
}

int get_sid(int moduleTypeIn,int motorTypeIn)
{
    int sid = 0;
    switch(moduleTypeIn)
    {
      case ModuleType::MT_DJ1_PCR_REAGENT:
      {
          sid = get_sid_in_moudle_djq(motorTypeIn);//20;//49;
      }
      break;
      case ModuleType::MT_DJ2_PU_REAGENT:
      {
          sid = get_sid_in_moudle_djp(motorTypeIn);//21;//50;
      }
      break;
      case ModuleType::MT_DP8:
      {
          sid = get_sid_in_moudle_dp8(motorTypeIn);//22;//51;
      }
      break;
      case ModuleType::MT_DP1:
      {
          sid = get_sid_in_moudle_dp1(motorTypeIn);//22;//51;
      }
      break;
      case ModuleType::MT_OPEN_LID:
      {
          sid = get_sid_in_moudle_openlid(motorTypeIn);//22;//51;
      }
      break;
      case ModuleType::MT_SHAKE_HEAT:
      {
          sid = 0;
      }
      break;
      case ModuleType::MT_HEAT_SEAL:
      {
          sid = get_sid_in_moudle_seal(motorTypeIn);//22;//51;
      }
      break;
      case ModuleType::MT_QPCR1:
      {
          sid = get_sid_in_moudle_qpcr1(motorTypeIn);//22;//51;
      }
      break;
      case ModuleType::MT_QPCR2:
      {
          sid = get_sid_in_moudle_qpcr2(motorTypeIn);//22;//51;
      }
      break;
      default:
      break;
    }

    return sid;
}

int convertPosDjq(const Position& grpcPos,location_layout * locOut)
{
    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    switch(posTypeIn)
    {
        case PosType::PT_DJ1_PCR_REAGENT_A:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.row();
           locOut->location_type = DJ_QPCR_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_REAGENT_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.row();
           locOut->location_type = DJ_QPCR_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_CLEAN:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->location_type = DJ_QPCR_CLEANPOOL;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_BOARD:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.index();
           locOut->column_x = grpcPos.column();
           locOut->row_y = grpcPos.row();
           locOut->location_type = DJ_QPCR_48HOLES;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_BARCODE:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.index();
           locOut->location_type = DJ_QPCR_BARCODE;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_TRANS:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->location_type = DJ_QPCR_TRANS;
           ret = 0;
        }
        break;
        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosDjp(const Position& grpcPos,location_layout * locOut)
{
    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    switch(posTypeIn)
    {
        case PosType::PT_DJ2_PU_REAGENT_A:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.row();
           locOut->location_type = DJ_PURIFY_REAGENT;
           if(locOut->indexY == 6 || locOut->indexY == 7)
           {
              locOut->indexY -= 6;
              locOut->location_type = DJ_PURIFY_SPLIT; 
           }
           ret = 0;
        }
        break;
        case PosType::PT_DJ2_PU_REAGENT_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.row();
           locOut->location_type = DJ_PURIFY_REAGENT;
           if(locOut->indexY == 6 || locOut->indexY == 7)
           {
              locOut->indexY -= 6;
              locOut->location_type = DJ_PURIFY_SPLIT; 
           }
           ret = 0;
        }
        break;      
        case PosType::PT_DJ2_PU_CLEAN:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->location_type = DJ_PURIFY_CLEANPOOL;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DJ2_PU_8TUBE_A:
        {
           int index_grpc = grpcPos.index(); 
           locOut->indexX = index_grpc/3;
           locOut->indexY = index_grpc%3;
           locOut->row_y = grpcPos.row();
           locOut->column_x = 0;
           locOut->location_type = DJ_PURIFY_8HOLES_A;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DJ2_PU_8TUBE_B:
        {
           int index_grpc = grpcPos.index(); 
           locOut->indexX = index_grpc/3;
           locOut->indexY = index_grpc%3;
           locOut->row_y = grpcPos.row();
           locOut->column_x = 0;
           locOut->location_type = DJ_PURIFY_8HOLES_B;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_PU_MAGNETIC_VIBRATION:
        {
           int index_grpc = grpcPos.index(); 
           locOut->column_x = index_grpc;
           locOut->location_type = DJ_PURIFY_MAG_SHAKE;
           ret = 0;
        }
        break;
        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosDp1(const Position& grpcPos,location_layout * locOut)
{
    int ret = -1;
    int posTypeIn = grpcPos.postype();
    //printf("enter in convertPosDp1\n");
    memset(locOut,0,sizeof(location_layout));
    switch(posTypeIn)
    {
        case PosType::PT_DP1_DJ2_PU_8TUBE_A:
        {
           int indexTemp = grpcPos.index();
           locOut->indexX = indexTemp/3;
           locOut->indexY = indexTemp%3;
           locOut->row_y = grpcPos.row();
           locOut->location_type = DP1_8HOLES_SPIT_A;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DJ2_PU_8TUBE_B:
        {
           int indexTemp = grpcPos.index();
           locOut->indexX = indexTemp/3;
           locOut->indexY = indexTemp%3;
           locOut->row_y = grpcPos.row();
           locOut->location_type = DP1_8HOLES_SPIT_B;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_PU_MAGNETIC_VIBRATION:
        {
           int indexTemp = grpcPos.index();

           locOut->column_x = indexTemp;
           //locOut->column_x = indexTemp;
           //locOut->indexY = grpcPos.row();
           locOut->location_type = DP1_MAG_SHAKE_JAW;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_8TUBE_BUFFER:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->row_y = grpcPos.row();
           locOut->location_type = DP1_8HOLES_SPIT_BUFF;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_SAMPLE_RACK_A:
        {
           locOut->indexX = grpcPos.index();
           locOut->indexY = grpcPos.row();
           locOut->row_y = 0;
           locOut->column_x = 0;
           locOut->location_type = DP1_TUBE_JAW;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_SAMPLE_RACK_B:
        {
           locOut->indexX = grpcPos.index() + 2;
           locOut->indexY = grpcPos.row();
           locOut->row_y = 0;
           locOut->column_x = 0;
           locOut->location_type = DP1_TUBE_JAW;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_REF_RACK_A:
        {
           locOut->indexX = grpcPos.index();
           locOut->indexY = grpcPos.row() + 24;
           locOut->row_y = 0;
           locOut->column_x = 0;
           locOut->location_type = DP1_TUBE_JAW;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_REF_RACK_B:
        {
           locOut->indexX = grpcPos.index() + 2;
           locOut->indexY = grpcPos.row() + 24;
           locOut->row_y = 0;
           locOut->column_x = 0;
           locOut->location_type = DP1_TUBE_JAW;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_SAMPLE_TIP_GET_A:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->row_y = grpcPos.row();
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP1_TIPS;
           ret = 0;
        }
        break;        
        case PosType::PT_DP1_SAMPLE_TIP_GET_B:
        {
           locOut->indexX = 1;
           locOut->indexY = 0;
           locOut->row_y = grpcPos.row();
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP1_TIPS;
           ret = 0;
        }
        break;  
        case PosType::PT_DP1_INNER_REF_TIP_GET_A:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->row_y = 0;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP1_TIPS_INTER_REF;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_INNER_REF_TIP_GET_B:
        {
           locOut->indexX = 1;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP1_TIPS_INTER_REF;
           ret = 0;
        }
        break;        
        case PosType::PT_DP1_OPEN_LID_SUCK:
        {
           locOut->location_type = DP1_OPENLID_SUCK;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DP8_SHAKE:
        {
           locOut->location_type = DP1_TUBE8_SHAKE_JAW;
           
           int indexTemp = grpcPos.index() + 1;

           locOut->indexX = indexTemp/3;
           locOut->indexY = indexTemp%3;           
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DP8_RECYCLE:
        {
           locOut->location_type = DP1_DROPTIP;
           ret = 0;
        }
        break;
        case PosType::PT_OPEN_LID_X_SUCK_WAIT:
        case PosType::PT_OPEN_LID_X_WORK_WAIT:
        {
           locOut->location_type = DP1_OPENLID_SUCK;
           ret = 0;
        }
        break;
        case PosType::PT_DJ2_PU_REAGENT_A:
        case PosType::PT_DJ2_PU_REAGENT_B:
        {
            locOut->indexY = grpcPos.row();
           locOut->location_type = DP1_REAGENT_JAW;
           ret = 0;
        }
        break;

        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosDp8(const Position& grpcPos,location_layout * locOut)
{

    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    switch(posTypeIn)
    {
        case PosType::PT_DP1_DP8_SHAKE:
        {
           int indexTemp = grpcPos.index() + 1;
           locOut->indexX = indexTemp/3;
           locOut->indexY = indexTemp%3;
           locOut->row_y = 0;
           locOut->column_x = 0;
           locOut->location_type = DP8_TUBE8_SHAKE;
           ret = 0;
        }
        break;
        case PosType::PT_DP1_DP8_RECYCLE:
        {
           locOut->location_type = DP8_DROPTIP;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_PCR_TRANS:
        {
           locOut->location_type = DP8_PCR_TRANS;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_PCR_BUFFER:
        {
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_PCR_BUFF_TIP;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_DNA_SAMPLE_A:
        {
           locOut->indexX = 0;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_DNA_BUFF_TIP;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_DNA_SAMPLE_B:
        {
           locOut->indexX = 1;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_DNA_BUFF_TIP;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_TS_TIP_GET_A:
        {
           int indexTemp = grpcPos.index();
           if(indexTemp>=3)
           {
               indexTemp ++;
           }
           locOut->indexX = indexTemp/3;
           locOut->indexY = indexTemp%3;
           
           locOut->row_y = 0;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_TIP48_PURIFY_A;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_TS_TIP_GET_B:
        {
            int indexTemp = grpcPos.index();
            if(indexTemp>=3)
            {
               indexTemp ++;
            }
            locOut->indexX = indexTemp/3;
            locOut->indexY = indexTemp%3;
            locOut->row_y = 0;
            locOut->column_x = grpcPos.column();
            locOut->location_type = DP8_TIP48_PURIFY_B;
            ret = 0;
        }
        break;        
        case PosType::PT_DP8_MOV_TIP_GET:
        {
            int indexTemp = grpcPos.index();
           locOut->indexX = 0;
           locOut->indexY = indexTemp;
           locOut->row_y = 0;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_TIP48_TRANS;
           ret = 0;
        }
        break;  
        case PosType::PT_DP8_TIP_BUFFER:
        {
           locOut->indexX = 0;
           locOut->indexY = 0;
           locOut->column_x = grpcPos.column();
           locOut->location_type = DP8_TIP48_BUFF;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER1_A:
        {
           locOut->indexX = 0;
           int columnGrpc = grpcPos.column();
           locOut->indexY = grpcPos.index();
           locOut->column_x = columnGrpc*4;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break; 
        case PosType::PT_DP8_CLEANER2_A:
        {
           locOut->indexX = 0;
           int columnGrpc = grpcPos.column();
           locOut->indexY = grpcPos.index();
           locOut->column_x = columnGrpc*4 + 1;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break; 
        case PosType::PT_DP8_ELUATE_A:
        {
           locOut->indexX = 0;
           int columnGrpc = grpcPos.column();
           locOut->indexY = grpcPos.index();
           locOut->column_x = columnGrpc*4 + 2;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;      
        case PosType::PT_DP8_CLEANER1_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc*4;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER2_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc*4 + 1;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_ELUATE_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc*4 + 2;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER3_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc*4 + 3;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER3_A:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc*4 + 3;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;         
        case PosType::PT_DP8_PUT_FILM:
        {
           locOut->location_type = DP8_FILM_SRC;
           ret = 0;
        }
        break;
        case PosType::PT_HEAT_SEAL_Y_WAIT:
        {
           locOut->location_type = DP8_HEAT_SEAL;
           ret = 0;
        }
        break;
        case PosType::PT_RECYCLE_LIQUID:
        {
           locOut->location_type = DP8_WASTE_LIQUID;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER_ELUATE_A:
        {
           locOut->indexX = 0;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER_ELUATE_B:
        {
           locOut->indexX = 1;
           locOut->indexY = grpcPos.index();
           int columnGrpc = grpcPos.column();
           locOut->column_x = columnGrpc;
           locOut->location_type = DP8_REAGENT;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_CLEANER_ELUATE_A_BARCODE:
        case PosType::PT_DP8_CLEANER_ELUATE_B_BARCODE:
        {
           if(PosType::PT_DP8_CLEANER_ELUATE_A_BARCODE == posTypeIn)
           {
               locOut->indexX = 1;
           }
           else
           {
               locOut->indexX = 0;
           }
           
           locOut->indexY = grpcPos.index();
           locOut->location_type = DP8_SCANCODE;
           ret = 0;
        }
        break;
        case PosType::PT_DP8_WASTE_CLOSE:
        case PosType::PT_DP8_WASTE1: 
        case PosType::PT_DP8_WASTE2: 
        case PosType::PT_DP8_EFFLUENT:
        {           
           //locOut->indexY = grpcPos.index();
           locOut->location_type = posTypeIn - PosType::PT_DP8_WASTE_CLOSE;
           ret = 0;
        }
        break;
        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosLogistic(const Position& grpcPos,location_layout * locOut)
{

    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    switch(posTypeIn)
    {
        case PosType::PT_TRANS_CONNECT:
        {
           locOut->location_type = LOG1_EXCHANGE12;
           ret = 0;
        }
        break;
        case PosType::PT_TRANS_CONNECT_BREAK:
        {
           locOut->location_type = LOG1_DOWN;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_TRANS:
        {
           locOut->location_type = LOG1_PCR_BOARD;
           ret = 0;
        }
        break;
        case PosType::PT_TRANS_BASE_3RD:        
        {
           locOut->location_type = LOG2_EXCHANGE23;
           ret = 0;
        }
        break;
        case PosType::PT_TRANS_TRAY_3RD:
        {
           locOut->location_type = LOG3_UP;
           ret = 0;
        }
        break;
        case PosType::PT_DJ1_PCR_BOARD:        
        {
           locOut->location_type = DJ_QPCR_BOARDJAW;
           locOut->indexY = grpcPos.index();
           ret = 0;
        }
        break;

        case PosType::PT_QPCR_GET_PCR_WAIT:
        {
            locOut->location_type = LOG3_QPCR_GET;
            ret = 0;
        }
        break;
        case PosType::PT_QPCR_RECYCLE:
        {
            locOut->location_type = LOG3_QPCR_DROP;
            ret = 0;
        }
        break;
        case PosType::PT_QPCR1_METAL_BATH_Y_WAIT:
        {
            locOut->location_type = LOG3_BATH1;
            ret = 0;            
        }
        break;
        case PosType::PT_QPCR2_METAL_BATH_Y_WAIT:
        {
            locOut->location_type = LOG3_BATH2;
            ret = 0;            
        }
        break;

        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosQpcr(const Position& grpcPos,location_layout * locOut)
{

    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    std::cout << "enter in convertPosQpcr,posType:"<<posTypeIn<<std::endl;
    switch(posTypeIn)
    {
        case PosType::PT_QPCR1_METAL_BATH_Y_WAIT:
        case PosType::PT_QPCR2_METAL_BATH_Y_WAIT:
        {
           locOut->location_type = QPCR1_BATH_X_WAIT;
           ret = 0;
        }
        break;
        case PosType::PT_QPCR1_METAL_BATH_Y_IN_Z_DOWN:
        case PosType::PT_QPCR2_METAL_BATH_Y_IN_Z_DOWN:
        {
           locOut->location_type = QPCR1_BATH_X_WORK;
           ret = 0;
        }
        break;
        // case PosType::PT_QPCR1_METAL_BATH_Z_DOWN:
        // case PosType::PT_QPCR2_METAL_BATH_Z_DOWN:
        // {
        //    locOut->location_type = QPCR1_BATH_Z_WAIT;
        //    ret = 0;
        // }
        // break;
        case PosType::PT_QPCR1_METAL_BATH_Z_UP:
        case PosType::PT_QPCR2_METAL_BATH_Z_UP:
        {
           locOut->location_type = QPCR1_BATH_Z_WORK;
           ret = 0;
        }
        break;

        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosSeal(const Position& grpcPos,location_layout * locOut)
{
    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    std::cout << "enter in convertPosSeal,posType:"<<posTypeIn<<std::endl;
    switch(posTypeIn)
    {
        case PosType::PT_HEAT_SEAL_Y_WAIT:
        {
           locOut->location_type = SEAL_X_WAIT;
           ret = 0;
        }
        break;
        case PosType::PT_HEAT_SEAL_Y_WORK:
        {
           locOut->location_type = SEAL_X_WORK;
           ret = 0;
        }
        break;
        case PosType::PT_HEAT_SEAL_Z_UP:
        {
           locOut->location_type = SEAL_Z_WAIT;
           ret = 0;
        }
        break;
        case PosType::PT_HEAT_SEAL_Z_DOWN:
        {
           locOut->location_type = SEAL_Z_WORK;
           ret = 0;
        }
        break;

        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertPosOpenlid(const Position& grpcPos,location_layout * locOut)
{
    int ret = -1;
    int posTypeIn = grpcPos.postype();
    memset(locOut,0,sizeof(location_layout));
    std::cout << "enter in convertPosSeal,posType:"<<posTypeIn<<std::endl;
    switch(posTypeIn)
    {
        case PosType::PT_OPEN_LID_X_SUCK_WAIT:
        {
           locOut->location_type = OPENLID_X_SUCK;
           ret = 0;
        }
        break;
        case PosType::PT_OPEN_LID_X_WORK_WAIT:
        {
           locOut->location_type = OPENLID_X_OPEN;
           ret = 0;
        }
        break;
        case PosType::PT_OPEN_LID_Z_OPEN:
        {
           locOut->location_type = OPENLID_Z_OPEN;
           ret = 0;
        }
        break;
        case PosType::PT_OPEN_LID_Z_ClOSE:
        {
           locOut->location_type = OPENLID_Z_WAIT;
           ret = 0;
        }
        break;

        default:
        ret = -1;
        break;
    }

    return ret;
}

int convertGRPCPos(int moduleTypeIn, const Position& grpcPos,void * pstLocOut)
{
    location_layout * locOut = (location_layout *)pstLocOut;
    switch (moduleTypeIn)
    {
        case ModuleType::MT_DJ1_PCR_REAGENT:
        {
            return convertPosDjq(grpcPos,locOut);
        }
        break;
        case ModuleType::MT_DJ2_PU_REAGENT:
        {
            return convertPosDjp(grpcPos,locOut);
        }
        break;
        case ModuleType::MT_DP1:
        {
            return convertPosDp1(grpcPos,locOut);
        }
        break; 
        case ModuleType::MT_DP8:
        case ModuleType::MT_DP8_1:
        {
            return convertPosDp8(grpcPos,locOut);
        }
        break; 
        case ModuleType::MT_LOGISTICS:
        {
            return convertPosLogistic(grpcPos,locOut);
        }
        break;
        case ModuleType::MT_QPCR1:
        case ModuleType::MT_QPCR2:
        {
            return convertPosQpcr(grpcPos,locOut);
        }
        break;
        case ModuleType::MT_HEAT_SEAL:
        {
            return convertPosSeal(grpcPos,locOut);
        }
        break; 
        case ModuleType::MT_OPEN_LID:
        {
            return convertPosOpenlid(grpcPos,locOut);
        }
        break;       
        default:
        {
            std::cout<<"position is not valid"<<std::endl;
            return -1;
        }
        break;
    }
}

// int convertPosition(int moduleTypeIn, const Position& grpcPos,void * locationOut)
// {
//     CGpLayout * pLayout = CGpLayout::get_instance();
    
//     location_layout paramIn; 
    
//     memset(&paramIn,0,sizeof(location_layout));

//     // paramIn.location_type = DP1_TIPS;
//     // paramIn.indexX = 0;
//     // paramIn.indexY = 0;
//     // paramIn.row_x = 2;
//     // paramIn.column_y = 3;

//     convertGRPCPos(moduleTypeIn,grpcPos,&paramIn);

//     std::cout <<"after convert,loc_type:"<<paramIn.location_type
//     <<",moduleX:"<<paramIn.indexX<<",moduleY:"<<paramIn.indexY
//     <<",column_x:"<<paramIn.column_x<<",row_y:"<<paramIn.row_y<<std::endl;

//     int convertRet = pLayout->convertToAxisLoc(&paramIn,(location_axis*)locationOut);

// }


int convertModule(int moduleTypeIn)
{
    switch (moduleTypeIn)
    {
        case ModuleType::MT_DJ1_PCR_REAGENT:
        {
            return MODULE_DJ_QPCR;
        }
        break;
        case ModuleType::MT_DJ2_PU_REAGENT:
        {
            return MODULE_DJ_PURIFY;
        }
        break;
        case ModuleType::MT_DP1:
        {
            return MODULE_DP1;
        }
        break; 
        case ModuleType::MT_DP8:
        {
            return MODULE_DP8;
        }
        break;
        case ModuleType::MT_HEAT_SEAL:
        {
            return MODULE_SEAL;
        }
        break;
        case ModuleType::MT_SHAKE_HEAT:
        {
            return MODULE_SHAKE;
        }
        break; 
        case ModuleType::MT_OPEN_LID:
        {
            return MODULE_OPENLID;
        }
        break; 
        case ModuleType::MT_QPCR1:
        {
            return MODULE_QPCR1;
        }
        break;
        case ModuleType::MT_QPCR2:
        {
            return MODULE_QPCR2;
        }
        break;  
        case ModuleType::MT_DP8_1:
        {
            return MODULE_DP8_1;
        }
        break;
        case ModuleType::MT_LOGISTICS:
        {
            return MODULE_LOGISTIC;
        }
        break;       
        default:
        {
            std::cout<<"position is not valid"<<std::endl;
            return -1;
        }
        break;
    }
}

int convertLog1PosType(int posTypeIn)
{
    int ret = -1;
    switch(posTypeIn)
    {
        case GPRPC::PosType::PT_DJ1_PCR_TRANS:
        {
            ret = LOG1_PCR_BOARD;     
        }
        break;
        case GPRPC::PosType::PT_TRANS_CONNECT:
        {
            ret = LOG1_EXCHANGE12; 
        }
        break;
        case GPRPC::PosType::PT_TRANS_CONNECT_BREAK:
        {
            ret = LOG1_DOWN;             
        }
        break;
        default:
        break;
    }
    return ret;
}

int convertLog2PosType(int posTypeIn)
{
    int ret = -1;
    switch(posTypeIn)
    {
        case GPRPC::PosType::PT_TRANS_CONNECT:
        {
            ret = LOG2_EXCHANGE12; 
        }
        break;
        case GPRPC::PosType::PT_TRANS_BASE_3RD:
        case GPRPC::PosType::PT_TRANS_TRAY_3RD:
        {
            ret = LOG2_EXCHANGE23;             
        }
        break;
        
        default:
        break;
    }
    return ret;
}

int convertLog3PosType(int posTypeIn)
{
    int ret = -1;
    switch(posTypeIn)
    {
        case GPRPC::PosType::PT_TRANS_BASE_3RD:
        {
            ret = LOG3_QPCR_GET;             
        }
        break;
        case GPRPC::PosType::PT_TRANS_TRAY_3RD:
        {
            ret = LOG3_UP; 
        }
        break;
        default:
        break;
    }
    return ret;
}

int convertLogicPostype(int submoule,int grpcTypeIn)
{
    int ret = -1;
    switch(submoule)
    {
        case SUB_MODULE_LOG1:
        {
            ret = convertLog1PosType(grpcTypeIn);
        }
        break;
        case SUB_MODULE_LOG2:
        {
            ret = convertLog2PosType(grpcTypeIn);            
        }
        break;
        case SUB_MODULE_LOG3:
        {
            ret = convertLog3PosType(grpcTypeIn);            
        }
        break;
    }
    return ret;
}
